
package edu.uts.reekie.designer.implementation.edit;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;

import edu.uts.reekie.designer.edit.EditPartFactoryBase;
import edu.uts.reekie.designer.edit.ViewDiagramEditPart;
import edu.uts.reekie.designer.implementation.figures.ConcreteFigureFactory;
import edu.uts.reekie.designer.implementation.model.ConcreteModelFactory;
import edu.uts.reekie.designer.implementation.figures.*;
import edu.uts.reekie.designer.implementation.model.*;
import edu.uts.reekie.designer.figures.*;
import edu.uts.reekie.designer.model.*;


public class ViewPartFactory
	extends EditPartFactoryBase
{

public EditPart createEditPart(EditPart context, Object model) {
	EditPart ep = null;
	
	ModelFactory mf = createModelFactory();
	FigureFactory ff = createFigureFactory();
	
	if (model instanceof Connector)
		ep = new ConnectorEditPart();
	
	else if (model instanceof ContainerComponent)
		ep = new ContainerComponentEditPart(mf,ff);
	
	else if (model instanceof InfrastructureComponent)
		ep = new InfrastructureComponentEditPart(mf,ff);


	else if (model instanceof ApplicationComponent)
		ep = new ApplicationComponentEditPart(mf,ff);
	
	else if (model instanceof FileComponent)
		ep = new FileComponentEditPart(mf,ff);
	
	else if (model instanceof ViewExternalInterface)
		ep = new ViewExternalInterfaceEditPart(mf,ff);
	
	//Note that subclasses of ViewDiagram have already been matched above, like Circuit
	else if (model instanceof ViewDiagram)
		ep = new ViewDiagramEditPart(mf,ff);
	
	if (ep!=null) {
		ep.setModel(model);
		return ep;
	} else {
		return super.createEditPart(context, model);
	}
	
}


@Override
protected FigureFactory createFigureFactory() {
	return new ConcreteFigureFactory();
}

@Override
protected ModelFactory createModelFactory() {
 
	return new ConcreteModelFactory();
}

}
